<?php

/**
 *      [品牌空间] (C)2001-2010 Comsenz Inc.
 *      This is NOT a freeware, use is subject to license terms
 *
 *      $Id: ec.inc.php 5654 2011-02-24 07:39:28Z xuhui $
 */

if(!defined('IN_ADMIN')) {
	exit('Acess Denied');
}

if(submitcheck('valuesubmit')){
    
    if(!empty($_GET['op']) && $_GET['op'] == 'alipay') {
        DB::query("REPLACE INTO ".DB::table('settings')." (`variable`, `value`) VALUES
            ('alipay_account', '".$_POST['alipay_account']."'),
            ('alipay_partner', '".$_POST['alipay_partner']."'),
            ('alipay_securitycode', '".$_POST['alipay_securitycode']."'),
            ('alipay_creditdirectpay', '1')
        ");      
    } elseif(!empty($_GET['op']) && $_GET['op'] == 'tenpay') {
    	DB::query("REPLACE INTO ".DB::table('settings')." (`variable`, `value`) VALUES
            ('tenpay_direct', '1'),
            ('tenpay_bargainor', '".$_POST['tenpay_bargainor']."'),
            ('tenpay_key', '".$_POST['tenpay_key']."')
        ");
    } else {
        cpmsg('request error');
    }
    updatesettingcache();

	cpmsg('update_success', '?action=ec&op='.$_GET['op']);

} elseif(!empty($_GET['op']) && in_array($_GET['op'], array('alipay', 'tenpay'))) {
	if(!empty($_GET['checktype'])){
	include_once('./api/trade/api_'.$_GET['op'].'.php');
	$orderid = '';
	$price = 1;
	$requesturl = credit_payurl($price, $orderid);
	echo '<form id="payform" action="'.$requesturl.'" method="post"></form><script type="text/javascript" reload="1">document.getElementById(\'payform\').submit();</script>';
	}
	
    shownav('global', 'nav_ec_'.$_GET['op']);
    showsubmenu('nav_ec_'.$_GET['op']);
    $menuA = $_GET['op'] == 'tenpay'?1:0;
    $menuB = intval($menuA - 1);
	showsubmenu('nav_ec_'.$_GET['op'], array(
		array('nav_ec_tenpay', 'ec&op=tenpay', $menuA),
		array('nav_ec_alipay', 'ec&op=alipay', $menuB),
		
	));
    showtips('nav_ec_'.$_GET['op'].'_tips');
    showformheader('ec&op='.$_GET['op']);

    if($_GET['op'] == 'alipay') {
        list($_G['setting']['alipay_account'], $_G['setting']['alipay_partner'], $_G['setting']['alipay_securitycode'], $_G['setting']['alipay_creditdirectpay']) = explode("\t", authcode($_G['setting']['ec']['alipay'], 'DECODE', $_G['authkey']));
        showtableheader('ec_alipay_setting');
        showsetting('alipay_account', 'alipay_account', $_G['setting']['alipay_account'], 'text');
        showsetting('alipay_test', '', '<a target="_blank" href="'.B_URL.'admin.php?action=ec&op=alipay&checktype=alipay">'.lang('alipay_test').'</a>', 'p_pre');
        showtablefooter();

        showtableheader('ec_alipay_partner_settig');
        showsetting('alipay_partner', 'alipay_partner', $_G['setting']['alipay_partner'], 'text');
        showsetting('alipay_securitycode', 'alipay_securitycode', $_G['setting']['alipay_securitycode'], 'text');
       // showsetting('alipay_creditdirectpay', 'alipay_creditdirectpay', $_G['setting']['alipay_creditdirectpay'], 'radio');


    } elseif($_GET['op'] == 'tenpay') {
        list($_G['setting']['tenpay_direct'], $_G['setting']['tenpay_bargainor'], $_G['setting']['tenpay_key']) = explode("\t", authcode($_G['setting']['ec']['tenpay'], 'DECODE', $_G['authkey']));

        showtableheader('ec_tenpay_direct_setting');
        showsetting('tenpay_bargainor', 'tenpay_bargainor', $_G['setting']['tenpay_bargainor'], 'text');
        showsetting('tenpay_key', 'tenpay_key', $_G['setting']['tenpay_key'], 'text');
        showsetting('tenpay_test', '', '<a target="_blank" href="'.B_URL.'admin.php?action=ec&op=tenpay&checktype=tenpay">'.lang('tenpay_test').'</a>', 'p_pre');

    }
    showsubmit('valuesubmit');
    showtablefooter();

    showformfooter();

} else {
    cpmsg('request error');

}

?>